-----------------------------------
-- 
-- Zone: Dynamis-Xarcabard
-- 
-----------------------------------
package.loaded["scripts/zones/Dynamis-Xarcabard/TextIDs"] = nil;
-----------------------------------

require("scripts/globals/settings");
require("scripts/zones/Dynamis-Xarcabard/TextIDs");

-----------------------------------
--  onInitialize
-----------------------------------

function onInitialize(zone)
end;

-----------------------------------
-- onZoneIn
-----------------------------------

function onZoneIn(player,prevZone)
	
	cs = -1;
	
	local realDay = os.time();
	local dynaWaitxDay = player:getVar("dynaWaitxDay");
	local dynaTimeLimit = (dynaWaitxDay + 10800); --TROAKCHANGE
	local dynaCooldown = (dynaWaitxDay + (BETWEEN_2DYNA_WAIT_TIME * 22 * 60 * 60)); --TROAKCHANGE
	local dynaLoc = player:getVar("dynaLoc"); --TROAKCHANGE
	
	if((player:getXPos() == 0) and (player:getYPos() == 0) and (player:getZPos() == 0)) then	
		player:setPos(569.600,-0.078,-270.000,90);
	end
	
	if((dynaTimeLimit > realDay) and (dynaLoc == 6)) then --TROAKCHANGE
	--TROAKCHANGE if((dynaWaitxDay + (BETWEEN_2DYNA_WAIT_TIME * 24 * 60 * 60)) < realDay or player:getVar("DynamisID") == GetServerVariable("[DynaXarcabard]UniqueID")) then
		if(player:isBcnmsFull() == 1) then
			if(player:hasStatusEffect(EFFECT_DYNAMIS, 0) == false) then
				inst = player:addPlayerToDynamis(1285);
				if(inst == 1)then
					player:bcnmEnter(1285);
				else
					 cs = 0;
				end
			else
				player:bcnmEnter(1285);
			end
		else
			inst = player:bcnmRegister(1285);
			
			if(inst == 1)then
				player:bcnmEnter(1285);
			else
				cs = 0;
			end
		end
	else
		cs = 0;
	end
	
	return cs;
	
end;

-----------------------------------
-- onRegionEnter          
-----------------------------------

function onRegionEnter(player,region)
end;

-----------------------------------
-- onEventUpdate
-----------------------------------

function onEventUpdate(player,csid,option)
--printf("CSID: %u",csid);
--printf("RESULT: %u",option);
end;

-----------------------------------
-- onEventFinish
-----------------------------------

function onEventFinish(player,csid,option)
--printf("CSID: %u",csid);
--printf("RESULT: %u",option);
	
	if(csid == 0) then
		player:setPos(569.312,-0.098,-270.158,90,0x70);
	end
	
end;